<?php
/**
 * WpHttpResponse.php
 * 
 * This file contains the class WpHttpResponse to be used for http responses
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage web.response
 */

/**
 * The interface to implement
 */
require_once (dirname(__FILE__).'/IWpResponse.php');

/**
 * The class to be used for http responses
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage web.response
 */
class WpHttpResponse implements IWpResponse
{
	private $_status = '200 OK';
	private $_headers = array();
	private $_body = null;
	private $startSending = false;
	
  /**
   * Add a header information (if response type supports headers)
   * @param object $name The name of the header information
   * @param object $value The information value
   */
  public function addHeader($name, $value)
  {
  	$this->_headers[$name] = $value;
  }

  /**
   * Send response
   */
  public function flush()
  {
  	//-- Send header only once --
	if ($this->startSending !== true) {
		header('HTTP/1.0 '.$this->_status);
		foreach ($this->_headers as $name => $value)
		{
			header($name.': '.$value);
		}
	}
	
	print($this->_body);
	$this->_headers = array();
	$this->_body = '';
	$this->startSending = true;
  }

  /**
   * Set the response status
   * @param string $status The status to set
   */
  public function setStatus($status)
  {
  	$this->_status = $status;
  }

  /**
   * Write data to the response
   * @param string $data The data to write to the response
   */
  public function write($data)
  {
  	$this->_body .= $data;
  }
}

/* End of file WpHttpResponse.php */
/* Location: ./wildpack/web/request/WpHttpResponse.php */ 
